﻿using System;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using MSAP.Framework.Interfaces;
using MSAP.Framework;

using Data;

namespace PLL.Notes
{
    public class NoteAdd_SAC : ServiceActionCommand
    {
        public NoteAdd_SAC(NotesServicePage _SP)
            : base( "CRUD_NOTE",
                    "NOTE_ADD", 
                    "Ajouter une note", 
                    "Ajouter une note.", 
                    _SP)
        {
            this.execute = parameter => DoIt(parameter);
            this.canExecute = canParameter => Check(canParameter);
        }

        private void DoIt(object parameter)
        {
            NotesServicePage nsp = this.ServicePage as NotesServicePage;
            Note note = nsp.TableNotes.CreateRecord();
            note.Date = DateTime.Now;
        }

        private bool Check(object parameter)
        {
            return true;
        }
    }
    public class NoteDelete_SAC : ServiceActionCommand
    {
        public NoteDelete_SAC(NotesServicePage _SP)
            : base("CRUD_NOTE",
                    "NOTE_DELETE",
                    "Supprimer une note",
                    "Supprimer une note.",
                    _SP)
        {
            this.execute = parameter => DoIt(parameter);
            this.canExecute = canParameter => Check(canParameter);
        }

        private void DoIt(object parameter)
        {
            NotesServicePage nsp = this.ServicePage as NotesServicePage;
            Note note = nsp.RecordsView.CurrentItem as Note;
            nsp.TableNotes.DeleteRecord(note.Oid);

        }

        private bool Check(object parameter)
        {
            NotesServicePage nsp = this.ServicePage as NotesServicePage;
            if (nsp.RecordsView.IsEmpty) return false;
            if (nsp.RecordsView.CurrentItem == null) return false;
            return true;
        }
    }
    public class NoteSave_SAC : ServiceActionCommand
    {
        public NoteSave_SAC(NotesServicePage _SP)
            : base("CRUD_NOTE",
                    "NOTE_SAVE",
                    "Sauvegarder les notes",
                    "Sauvegarde les notes..",
                    _SP)
        {
            this.execute = parameter => DoIt(parameter);
            this.canExecute = canParameter => Check(canParameter);
        }

        private void DoIt(object parameter)
        {
            NotesServicePage nsp = this.ServicePage as NotesServicePage;
            nsp.TableNotes.Save(@"c:\temp\notes.soap.xml");
        }

        private bool Check(object parameter)
        {
            return true;
        }
    }
    public class NoteLoad_SAC : ServiceActionCommand
    {
        public NoteLoad_SAC(NotesServicePage _SP)
            : base("CRUD_NOTE",
                    "NOTE_LOAD",
                    "Charger les notes",
                    "Charger les notes..",
                    _SP)
        {
            this.execute = parameter => DoIt(parameter);
            this.canExecute = canParameter => Check(canParameter);
        }

        private void DoIt(object parameter)
        {
            NotesServicePage nsp = this.ServicePage as NotesServicePage;
            nsp.TableNotes.Load(@"c:\temp\notes.soap.xml");
        }

        private bool Check(object parameter)
        {
            return true;
        }
    }
}
